package org.demo.five;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * 
 * @author  
 * @date    2010-10-24
 * @file    org.demo.five.UsingSortedSet.java
 */
public class UsingSortedSet {
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		List<Person> persons = Arrays.asList(
				new Person("Ted","Neward",39),
				new Person("Ron","Reynolds",38),
				new Person("Charlotte","Neward",38),
				new Person("Mattrew","Mccellough",18));
		
		SortedSet<Person> ss = new TreeSet(new Comparator<Person>() {
			public int compare(Person o1, Person o2) {
				return o1.getlastName().compareTo(o2.getlastName());
			}
		});
		
		ss.addAll(persons);
		for (Person p : ss){
			System.out.println(p.getFirstName() + " " + p.getlastName());
		}
	}
}
